<template>
  <div class="registerbox">
    <el-card class="gray-card no-border no-margin-top" shadow="never">
      <el-form ref="form" :model="form" class="form">
        <el-row>
          <el-form-item label="播放顺序：">
            <el-input v-model="form.msgOrder"></el-input>
          </el-form-item>
        </el-row>

        <el-row>
          <el-form-item label="标题：">
            <el-input v-model="form.msgTitle"></el-input>
          </el-form-item>
        </el-row>

        <el-row>
          <el-form-item label="通知内容：">
            <el-input
              type="textarea"
              class="textarea"
              v-model="form.msg"
            ></el-input>
          </el-form-item>
        </el-row>

        <el-form-item label="通告范围：">
          <el-select
            v-model="form.receiveId"
            placeholder="选择通告范围"
            class=""
          >
            <el-option
              v-for="item in type"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-form-item>
      </el-form>
    </el-card>
    <div class="details-foot">
      <div class="cell-btn">
        <el-button type="primary" @click.native="handleSubmit">确定</el-button>
        <el-button @click.native="handleClose">取消</el-button>
      </div>
    </div>
  </div>
</template>

<script>
import {
  getNotifyMsg,
  addNotifyMsg,
  updateNotifyMsg,
  delNotifyMsg
} from "@/api/business/notifyMsg";

export default {
  name: "addEdit",
  props: {
    isVisibleAdd: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      title: "新增通知",
      deptNode: null,
      type: [
        {
          value: 1,
          label: "全院"
        },
        {
          value: 2,
          label: "外科"
        },
        {
          value: 3,
          label: "内科"
        }
      ],
      form: {
        msgOrder: "",
        msgTitle: "",
        msg: "",
        receiveId: ""
      },
      editId: ""
    };
  },
  created() {},
  methods: {
    handleSubmit() {
      if (this.editId === "") {
        addNotifyMsg(this.form).then(res => {
          this.handleClose();
        });
      } else {
        updateNotifyMsg(this.form).then(res => {
          this.handleClose();
        });
      }
    },
    handleOpen(obj) {
      this.editId = obj.id;
      this.form.id = obj.id;
      this.form.receiveId = obj.receiveId;
      this.form.msg = obj.msg;
      this.form.msgTitle = obj.msgTitle;
      this.form.msgOrder = obj.msgOrder;
    },
    handleOpenAdd() {
      this.editId = "";
      this.form.id = "";
      this.form.receiveId = "";
      this.form.msg = "";
      this.form.msgTitle = "";
      this.form.msgOrder = "";
    },
    handleClose() {
      this.$emit("close", false);
    }
  }
};
</script>

<style lang="scss" scoped>
.el-row {
  margin-bottom: 20px;

  &:last-child {
    margin-bottom: 0;
  }
}

.el-col {
  border-radius: 4px;
}
</style>
